/**
 * Created by Administrator on 2017/4/10.
 */



$(function () {
    var limit = 20;
    var SEOval = '';


    function xin() {
        $.ajax({
            url: ctx + '/rentorder/selectRentOrdersCount',
            type: 'GET',
            success: function (data) {

                var text = data.split(',');

                var li = $('.CustomTabs ul li');

                if (text[0] > 0) {
                    if (li.eq(0).find('.CustomBadge').length > 0) {
                        li.eq(0).find('.CustomBadge').remove();
                        li.eq(0).Badge({data: {text: text[0] > 99 ? '99+' : text[0], state: 'No'}})
                    } else {
                        li.eq(0).Badge({data: {text: text[0] > 99 ? '99+' : text[0], state: 'No'}})
                    }
                }

                if (text[1] > 0) {
                    if (li.eq(7).find('.CustomBadge').length > 0) {
                        li.eq(7).find('.CustomBadge').remove();
                        li.eq(7).Badge({data: {text: text[1] > 99 ? '99+' : text[1], state: 'No'}})
                    } else {
                        li.eq(7).Badge({data: {text: text[1] > 99 ? '99+' : text[1], state: 'No'}})
                    }
                }

                if (text[2] > 0) {
                    if (li.eq(8).find('.CustomBadge').length > 0) {
                        li.eq(8).find('.CustomBadge').remove();
                        li.eq(8).Badge({data: {text: text[2] > 99 ? '99+' : text[2], state: 'No'}})
                    } else {
                        li.eq(8).Badge({data: {text: text[2] > 99 ? '99+' : text[2], state: 'No'}})
                    }
                }
            }
        })
    }

    xin();
    setInterval(function () {
        xin()
    }, 60000);


    $(".Nav .SEO .SEOButton").on("click", function () {
        SEOval = $(".Nav .SEO  input").val();
        ajaxFreshOrder(1, SEOval);
    });

    $(document).keyup(function (event) {
        switch (event.keyCode) {
            case 13:
                $(".Nav .SEO .SEOButton").click();
                break;
        }
    });
    ajaxFreshOrder(1, SEOval);
    function ajaxFreshOrder(page, inquireVal) {

        var FreshOrder = {
            plateNoOrPassengerPhone: inquireVal || "",
            status: 35,
            'limit': limit,
            "pager.offset": (page - 1) * limit
        };
        $.ajax({
            url: ctx + '/rentorder/selectRentOrders',
            data: FreshOrder,
            type: "GET",
            success: function (data) {
                console.log(data)
                var Message = {
                    data: {
                        Thead: {
                            PullDownAction: "操作",
                            OddNumbers: "单号",
                            totalFree: '总金额',
                            payed: '租金',
                            shopName: "门店",
                            TakeCarWay: "取车地址",
                            CarWay: "还车地址",
                            LeaseTime: "预约时间",
                            CarTime: "还车时间",
                            reReturnTime: "续租时间",
                            CustomerName: "客户名称",
                            CustomerPhone: "客户电话",
                            PlateNumbers: "车辆牌号",
                            VehicleModel: "车辆型号",
                            // CharterBase: "租金标准",
                            PaysTheRent: "租车押金",
                            ViolationOfTheDeposit: "违章押金",
                            // GrantAmountInAdvance: "预授额度",
                            SubordinateCompanies: "所属公司",
                            Remark: "备注"
                        },
                        Tbody: []

                    }
                };
                for (var i = 0; i < data.content.length; i++) {
                    (function () {
                        var index = i;
                        var val = {
                            id: data.content[i].id,
                            PullDownAction: {
                                Default: {
                                    name: '完成订单',
                                    action: function () {
                                        var mode = {
                                            data: {
                                                Title: '完成订单提示',
                                                Content: '是否要完成此订单？',
                                                OkChange: function (e, Romve) {

                                                    var isBackPeccancyForegift = true;
                                                    var isBackPrepayRent = true;
                                                    if (data.content[index].isBackPeccancyForegift == 2 || data.content[index].isBackPeccancyForegift == 0) {
                                                        isBackPeccancyForegift = true;
                                                    } else {
                                                        isBackPeccancyForegift = false
                                                    }
                                                    if (data.content[index].isBackPrepayRent == 2 || data.content[index].isBackPrepayRent == 0) {
                                                        isBackPrepayRent = true;
                                                    } else {
                                                        isBackPrepayRent = false;
                                                    }
                                                    if (isBackPeccancyForegift && isBackPrepayRent) {
                                                        $.ajax({
                                                            url: ctx + '/rentorder/over',
                                                            data: {
                                                                id: data.content[index].id
                                                            },
                                                            type: 'POST',
                                                            success: function (data) {
                                                                if (data.message == '订单状态修改成功') {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '订单处理完成！',
                                                                            state: 'Ok'
                                                                        }
                                                                    });
                                                                    ajaxFreshOrder(1, SEOval);
                                                                } else if (data.message == '违章未全部处理') {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '请检查该订单的  违章是否处理！',
                                                                            state: 'No'
                                                                        }
                                                                    });

                                                                }
                                                            }
                                                        })
                                                    } else {
                                                        $('body').Overlays({
                                                            data: {
                                                                text: '请检查该订单的  违章是否处理  租车押金是否退换  违章押金是否退换！',
                                                                state: 'No'
                                                            }
                                                        })
                                                    }
                                                }
                                            },
                                            OkHide: true
                                        };
                                        $('body').ModalBox(mode)
                                    }
                                },
                                data: [
                                    {
                                        name: '查看订单',
                                        action: function (e) {
                                            window.location.href = ctx + '/rentorder/orderinfo?id=' + data.content[index].id;
                                        }
                                    },
                                    {
                                        name: '处理违章',
                                        action: function (e) {

                                            function BreakRecord() {
                                                var id = e.parent().parent().parent().parent().data('id');
                                                $.ajax({
                                                    url: ctx + '/rentorder/selectRentOrder',
                                                    data: {
                                                        id: id
                                                    },
                                                    success: function (data) {
                                                        var Data = data;
                                                        $.ajax({
                                                            url: ctx + '/rentorder/selectPeccancysByOrderId',
                                                            data: {orderId: id},
                                                            success: function (data) {
                                                                var breakOption = {
                                                                    data: {
                                                                        Title: "违章记录处理",
                                                                        Content: {},
                                                                        OkChange: function (e) {

                                                                        }
                                                                    }
                                                                };
                                                                var CustomOrder = {
                                                                    data: {
                                                                        Thead: {
                                                                            BreakTime: '违章时间',
                                                                            BreakGrade: '违章分数',
                                                                            BreakMoney: '违章金额(元)',
                                                                            BreakDescribe: '违章描述',
                                                                            Dispose: '处理',
                                                                            InformClient: '通知客户'
                                                                        },
                                                                        Tbody: []
                                                                    }
                                                                };
                                                                for (var i = 0; i < data.length; i++) {
                                                                    (function () {
                                                                        var index = i;
                                                                        var PushOption = {
                                                                            id: data[index].id,
                                                                            BreakTime: $().Timestamp.TimestampDate(data[index].time),
                                                                            BreakGrade: data[index].deductMarks,
                                                                            BreakMoney: data[index].amerce,
                                                                            BreakDescribe: data[index].reason,
                                                                            ButtonAction: '',
                                                                            InformClient: '通知客户'
                                                                        };
                                                                        CustomOrder.data.Tbody.push(PushOption);
                                                                        var chuliSate = true;
                                                                        if (data[index].status == 0) {
                                                                            PushOption.ButtonAction = {
                                                                                name: '处理',
                                                                                Action: function (e) {

                                                                                    function chulifn() {
                                                                                        if (chuliSate) {
                                                                                            chuliSate = false;
                                                                                            var timestamp = (new Date()).valueOf();
                                                                                            var id = e.parent().parent().data('id');
                                                                                            var Dispose = {
                                                                                                data: {
                                                                                                    Title: '处理违章',
                                                                                                    Content: '确认这个违章已处理？',
                                                                                                    OkChange: function (e) {
                                                                                                        $.ajax({
                                                                                                            url: ctx + '/rentorder/postPeccancy',
                                                                                                            data: {
                                                                                                                id: id,
                                                                                                                status: 1
                                                                                                            },
                                                                                                            type: 'POST',
                                                                                                            success: function (data) {
                                                                                                                if (data.message == '修改状态成功') {
                                                                                                                    new $().Overlays({
                                                                                                                        data: {
                                                                                                                            text: '处理成功！',
                                                                                                                            state: 'Ok'
                                                                                                                        }
                                                                                                                    })
                                                                                                                } else {
                                                                                                                    new $().Overlays({
                                                                                                                        data: {
                                                                                                                            text: '处理失败！',
                                                                                                                            state: 'No'
                                                                                                                        }
                                                                                                                    })
                                                                                                                }
                                                                                                            }
                                                                                                        });


                                                                                                        $('body .CustomModalBox[custommodalboxlength="0"]').remove();
                                                                                                        $('body .CustomModalBox[custommodalboxlength="1"]').remove();
                                                                                                        BreakRecord()

                                                                                                    }
                                                                                                }
                                                                                            };
                                                                                            $('body').ModalBox(Dispose)
                                                                                            // $('body').ModalBox(Dispose);
                                                                                        }
                                                                                    }

                                                                                    chulifn()

                                                                                }
                                                                            }
                                                                        } else {
                                                                            PushOption.ButtonAction = '已处理'
                                                                        }
                                                                    })()
                                                                }


                                                                breakOption.data.Content = {
                                                                    CustomOrderAction: '<div class="BreakAction CustomClear" ><div class="BreakActionAdd">添加</div></div>',
                                                                    CustomOrder: '<div class="ServiceOrder"></div>'
                                                                };


                                                                $('body').ModalBox(breakOption);

                                                                $('body').find('.CustomModalBox').find('.ServiceOrder').Order(CustomOrder);

                                                                $('.CustomModalBox').find('.BreakActionAdd').on('click', function (e) {
                                                                    e.stopPropagation();
                                                                    {
                                                                        var BreakTitme = null;
                                                                        var Address = null;
                                                                        var Grade = null;
                                                                        var Money = null;
                                                                        var Describe = null;

                                                                        var breakOption1 = {
                                                                            data: {
                                                                                Title: "添加违章",
                                                                                Content: '',
                                                                                OkChange: function (e, Remove) {
                                                                                    if (BreakTitme && Address && Grade && Money && Describe) {
                                                                                        var BreakItmeDta = {
                                                                                            orderId: id,
                                                                                            passengerId: Data.passengerId,
                                                                                            time: BreakTitme,
                                                                                            deductMarks: Grade,
                                                                                            amerce: Money,
                                                                                            reason: Describe,
                                                                                            address: Address,
                                                                                            plateNo: Data.plateNo,
                                                                                            passengerName: Data.passengerName,
                                                                                            status: 0
                                                                                        };
                                                                                        $.ajax({
                                                                                            url: ctx + '/rentorder/addPeccancy',
                                                                                            data: BreakItmeDta,
                                                                                            type: 'POST',
                                                                                            success: function (data) {

                                                                                                if (data.message == '创建成功') {
                                                                                                    new $().Overlays({
                                                                                                        data: {
                                                                                                            text: '添加成功',
                                                                                                            state: 'Ok'
                                                                                                        }
                                                                                                    });
                                                                                                    $('body .CustomModalBox[custommodalboxlength="0"]').remove();
                                                                                                    $('body .datepicker').remove();
                                                                                                    BreakTitme = null;
                                                                                                    Address = null;
                                                                                                    Grade = null;
                                                                                                    Money = null;
                                                                                                    Describe = null;
                                                                                                    Remove();
                                                                                                    BreakRecord();
                                                                                                } else {
                                                                                                    new $().Overlays({
                                                                                                        data: {
                                                                                                            text: '添加失败',
                                                                                                            state: 'No'
                                                                                                        }
                                                                                                    })
                                                                                                }
                                                                                            }
                                                                                        });
                                                                                    } else {
                                                                                        new $().Overlays({
                                                                                            data: {
                                                                                                text: '请检查信息格式是否正确',
                                                                                                state: 'No'
                                                                                            }
                                                                                        })
                                                                                    }
                                                                                },
                                                                                CancelChange: function () {
                                                                                    $('body .datepicker').remove();
                                                                                }
                                                                            },
                                                                            OKHide: true
                                                                        };


                                                                        var AddViolation = $('<div class="AddViolation"></div>');
                                                                        var Rows1 = $('<div  class="rows"></div>');
                                                                        var Name1 = $('<span class="RowsName"><em>*</em></span>').append('违章时间：');
                                                                        var BreakTime = $('<input  type="text" class="BreakTime">');
                                                                        var xianzaisj = new Date();
                                                                        var shijian = Date.parse(new Date(xianzaisj.getFullYear(), xianzaisj.getMonth(), (xianzaisj.getDate() + 1), xianzaisj.getHours(), xianzaisj.getMinutes(), xianzaisj.getSeconds(), 0)) / 1000;
                                                                        BreakTime.datetimepicker({
                                                                            format: "yyyy-mm-dd HH:ii",
                                                                            language: 'zh-CN',
                                                                            showMeridian: true,
                                                                            autoclose: true,
                                                                            todayBtn: true,
                                                                            endDate: $().Timestamp.TimestampDate(shijian)
                                                                        }).on('change', function () {
                                                                            var Titme = $(this).val();
                                                                            BreakTitme = $().Timestamp.DateTimestamp(Titme);
                                                                        });
                                                                        Rows1.append(Name1).append(BreakTime);
                                                                        AddViolation.append(Rows1);
                                                                        var Rows2 = $('<div  class="rows"></div>');
                                                                        var Name2 = $('<span class="RowsName"><em>*</em></span>').append('违章地址：');
                                                                        var BreakAddress = $('<input  type="text" class="BreakAddress">');
                                                                        Rows1.append(Name2).append(BreakAddress);
                                                                        AddViolation.append(Rows2);
                                                                        var Rows3 = $('<div  class="rows"></div>');
                                                                        var Name3 = $('<span class="RowsName"><em>*</em></span>').append('违章分数：');
                                                                        var BreakGrade = $('<input  type="number" class="BreakGrade">');

                                                                        Rows1.append(Name3).append(BreakGrade);
                                                                        AddViolation.append(Rows3);
                                                                        var Rows4 = $('<div  class="rows"></div>');
                                                                        var Name4 = $('<span class="RowsName"><em>*</em></span>').append('违章金额：');
                                                                        var BreakMoney = $('<input  type="number" class="BreakMoney">');
                                                                        Rows1.append(Name4).append(BreakMoney);
                                                                        AddViolation.append(Rows4);
                                                                        var Rows5 = $('<div  class="rows"></div>');
                                                                        var Name5 = $('<span class="RowsName"><em>*</em></span>').append('描述：');
                                                                        var BreakDescribe = $('<input  type="text" class="BreakDescribe">');
                                                                        Rows1.append(Name5).append(BreakDescribe);
                                                                        AddViolation.append(Rows5);
                                                                        breakOption1.data.Content = AddViolation;

                                                                        $('body').ModalBox(breakOption1);

                                                                        $(document).on('input', 'body .CustomModalBox[custommodalboxlength="1"] .BreakAddress', function () {
                                                                            Address = $(this).val();
                                                                        });
                                                                        $(document).on('input', 'body .CustomModalBox[custommodalboxlength="1"] .BreakGrade', function () {
                                                                            Grade = $(this).val();
                                                                        });
                                                                        $(document).on('input', 'body .CustomModalBox[custommodalboxlength="1"] .BreakMoney', function () {
                                                                            Money = $(this).val();
                                                                        });
                                                                        $(document).on('input', 'body .CustomModalBox[custommodalboxlength="1"] .BreakDescribe', function () {
                                                                            Describe = $(this).val();
                                                                        })
                                                                    }
                                                                })

                                                            }
                                                        });
                                                    }
                                                })
                                            }

                                            BreakRecord()
                                        }
                                    }
                                ]
                            },
                            OddNumbers: data.content[i].orderNo,
                            totalFree: data.content[i].totalFee,
                            payed: '',
                            ShopName: data.content[i].shopName,
                            RetrievingMeans: data.content[index].takeCarWay == 1 ? data.content[index].startAddress : "门店自取",
                            ReturnType: data.content[index].backCarWay == 1 ? data.content[index].endAddress : '门店自还',
                            CarTime: $.fn.Timestamp.TimestampDate(data.content[i].backCarTime),
                            LeaseTime: $.fn.Timestamp.TimestampDate(data.content[i].rentTime),
                            reReturnTime: data.content[i].reRentTime ? $.fn.Timestamp.TimestampDate(data.content[i].reRentTime) : '无',
                            CustomerName: data.content[i].passengerName,
                            CustomerPhone: data.content[i].passengerPhone,
                            PlateNumbers: data.content[i].plateNo,
                            VehicleModel: data.content[i].category,
                            // CharterBase: data.content[i].CharterBase,
                            PaysTheRent: data.content[i].prepayRent,
                            ViolationOfTheDeposit: data.content[i].peccancyForegift,
                            GrantAmountInAdvance: data.content[i].companyName,
                            // SubordinateCompanies: data.data[i].SubordinateCompanies,
                            Remark: data.content[i].memo
                        };

                        switch (data.content[i].isPay) {
                            case 0:
                                val.payed = $('<span class="badge">未交付</span>');
                                break;
                            case 1:
                                val.payed = data.content[i].payed;
                                break;
                            case 2:
                                val.payed = data.content[i].payed;
                                break;
                            case 3:
                                val.payed = data.content[i].payed;
                                break;
                            case 4:
                                val.payed = '已结算';
                                break;
                        }


                        switch (data.content[i].isBackPrepayRent) {
                            case 0:
                                val.PaysTheRent = '未交付';
                                val.PullDownAction.data.push({
                                    name: '交租车押金',
                                    action: function (e) {

                                        var prepayRentTime = '';
                                        var prepayRent = '';
                                        var prepayRentType = 1;
                                        var yajinjiluData = {
                                            data: {
                                                Title: '交租车押金',
                                                Content: '',
                                                OkChange: function (e, Remove) {
                                                    var reRentTime = '';
                                                    var huanche;

                                                    function Ajax() {
                                                        $.ajax({
                                                            url: ctx + '/rentorder/deposit',
                                                            data: huanche,
                                                            type: 'POST',
                                                            success: function (data) {
                                                                if (data.message == "押金记录录入成功") {
                                                                    ajaxFreshOrder(1, SEOval);
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加租车押金成功！',
                                                                            state: 'Ok'
                                                                        }
                                                                    });
                                                                    ajaxFreshOrder(1, SEOval);
                                                                    xin();
                                                                    Remove()
                                                                } else {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加租车押金失败，请稍后重试！',
                                                                            state: 'No'
                                                                        }
                                                                    })
                                                                }
                                                            }
                                                        });
                                                        $('body .datepicker').remove();
                                                    }

                                                    if (prepayRentType == 1) {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            prepayRentTime: prepayRentTime,
                                                            prepayRent: prepayRent,
                                                            prepayRentType: prepayRentType
                                                        };
                                                        if (!huanche.prepayRent <= 0 && !huanche.prepayRentTime == '') {
                                                            Ajax()
                                                        } else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    } else {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            prepayRent: prepayRent,
                                                            prepayRentType: prepayRentType
                                                        };
                                                        if (!huanche.prepayRent <= 0) {
                                                            Ajax()
                                                        } else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    }


                                                },
                                                CancelChange: function () {
                                                    $('body .datepicker').remove();
                                                }
                                            },
                                            OKHide: true,

                                        };


                                        var ModContent = $('<div class="ModContent"></div>');
                                        var YSRows = $('<div class="Rows"><div class="Name"><em>*</em>租车押金额度：</div></div>');
                                        var Content = $('<div class="RowsContent"><input class="YsInput" type="number" /></div>');
                                        Content.find('.YsInput').on('input', function () {
                                            prepayRent = $(this).val();
                                            if (prepayRent < 0) {
                                                $(this).val('');
                                                prepayRent = 0;
                                            }
                                        });
                                        YSRows.append(Content);
                                        ModContent.append(YSRows);

                                        var YSRowsType = $('<div class="Rows"><div class="Name">交付类型：</div></div>');
                                        var Content2 = $('<div class="RowsContent CustomClear"><label><input class="rentCarInput" type="radio" name="rentCar" value="预授权" checked /><span>预授权交付</span></label><label><input class="rentCarInput" type="radio" name="rentCar" value="现金" /><span>现金交付</span></label></div>');
                                        YSRowsType.append(Content2);
                                        ModContent.append(YSRowsType);

                                        var TimeRows = $('<div class="Rows PreauthorizationTime"><div class="Name"><em>*</em>预授权到期时间：</div></div>');
                                        var Content1 = $('<div class="RowsContent"></div>');
                                        var TimeInput = $('<input class="TimeInput" type="text" readonly/>');
                                        var shijian = Date.parse(new Date()) / 1000;
                                        TimeInput.datetimepicker({
                                            format: "yyyy-mm-dd HH:ii",
                                            language: 'zh-CN',
                                            showMeridian: true,
                                            autoclose: true,
                                            todayBtn: true,
                                            startDate: $().Timestamp.TimestampDate(shijian)
                                        }).on('change', function () {
                                            var Titme = $(this).val();
                                            prepayRentTime = $().Timestamp.DateTimestamp(Titme);
                                        });
                                        Content1.append(TimeInput);
                                        TimeRows.append(Content1);
                                        ModContent.append(TimeRows);
                                        yajinjiluData.data.Content = ModContent;

                                        var rentCar = ModContent.find('.rentCarInput');
                                        for (var i = 0; i < rentCar.length; i++) {
                                            rentCar.eq(i).on('click', function () {
                                                switch ($(this).val()) {
                                                    case '预授权':
                                                        prepayRentType = 1;
                                                        ModContent.find('.PreauthorizationTime').css({
                                                            'opacity': 1,
                                                            'z-index': '100',
                                                            'display': 'inline-block'
                                                        });
                                                        break;
                                                    case '现金':
                                                        prepayRentType = 0;
                                                        ModContent.find('.PreauthorizationTime').css({
                                                            'opacity': 1,
                                                            'z-index': '-100',
                                                            'display': 'none'
                                                        });
                                                        break;
                                                }
                                            })
                                        }

                                        $('body').ModalBox(yajinjiluData);

                                    }
                                });
                                break;
                            case 1:
                                val.PaysTheRent = data.content[i].prepayRent;
                                val.PullDownAction.data.push({
                                    name: "退还租车押金",
                                    action: function (e) {
                                        var SingID = e.parent().parent().parent().parent().data().id;
                                        var SinglePin = {
                                            data: {
                                                Title: '退还租车押金',
                                                Content: "是否退还押金?"
                                                ,
                                                OkChange: function () {
                                                    var Single = {
                                                        id: SingID,
                                                        type: 0
                                                    };
                                                    $.ajax({
                                                        url: ctx + '/rentorder/backForegift',
                                                        data: Single,
                                                        type: 'POST',
                                                        success: function (data, status) {
                                                            if (status == "success") {
                                                                new $().Overlays({
                                                                    data: {
                                                                        text: '违章预售金退还成功！',
                                                                        state: 'Ok'
                                                                    }
                                                                });
                                                            }
                                                            if (status == "error") {
                                                                new $().Overlays({
                                                                    data: {
                                                                        text: '违章预售金退还失败！',
                                                                        state: 'On'
                                                                    }
                                                                });
                                                            }
                                                            ajaxFreshOrder(1)
                                                        }
                                                    })

                                                }
                                            }
                                        };
                                        $('body').ModalBox(SinglePin);
                                    }
                                })
                                break;
                            case 2:
                                val.PaysTheRent = '已退还';
                                break;
                        }
                        switch (data.content[i].isBackPeccancyForegift) {
                            case 0:
                                val.ViolationOfTheDeposit = '未交付';
                                val.PullDownAction.data.push(
                                    {
                                        name: '交违章押金',
                                        action: function (e) {


                                            var peccancyForegiftTime = '';
                                            var peccancyForegift = '';
                                            var peccancyForegiftType = 1;
                                            var yajinjiluData = {
                                                data: {
                                                    Title: '交违章押金',
                                                    Content: '',
                                                    OkChange: function (e) {
                                                        var reRentTime = '';
                                                        var huanche;
                                                        if (peccancyForegiftType == 1) {
                                                            huanche = {
                                                                id: data.content[index].id,
                                                                peccancyForegiftTime: peccancyForegiftTime,
                                                                peccancyForegift: peccancyForegift,
                                                                peccancyForegiftType: peccancyForegiftType
                                                            };
                                                        } else {
                                                            huanche = {
                                                                id: data.content[index].id,
                                                                peccancyForegift: peccancyForegift,
                                                                peccancyForegiftType: peccancyForegiftType
                                                            };
                                                        }

                                                        $.ajax({
                                                            url: ctx + '/rentorder/deposit',
                                                            data: huanche,
                                                            type: 'POST',
                                                            success: function (data) {

                                                                if (data.message == "押金记录录入成功") {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加违章押金成功！',
                                                                            state: 'Ok'
                                                                        }
                                                                    });
                                                                    ajaxFreshOrder(1, SEOval);
                                                                } else {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加违章押金失败，请稍后重试！',
                                                                            state: 'No'
                                                                        }
                                                                    })
                                                                }
                                                            }
                                                        });
                                                        $('body .datepicker').remove();
                                                    },
                                                    CancelChange: function () {
                                                        $('body .datepicker').remove();
                                                    }
                                                }
                                            };


                                            var ModContent = $('<div class="ModContent"></div>');
                                            var YSRows = $('<div class="Rows"><div class="Name"><em>*</em>违章押金额度：</div></div>');
                                            var Content = $('<div class="RowsContent"><input class="YsInput" type="number" /></div>');
                                            Content.find('.YsInput').on('input', function () {
                                                peccancyForegift = $(this).val()
                                            });
                                            YSRows.append(Content);
                                            ModContent.append(YSRows);

                                            var YSRowsType = $('<div class="Rows"><div class="Name">交付类型：</div></div>');
                                            var Content2 = $('<div class="RowsContent CustomClear"><label><input class="rentCarInput" type="radio" name="rentCar" value="预授权" checked /><span>预授权交付</span></label><label><input class="rentCarInput" type="radio" name="rentCar" value="现金" /><span>现金交付</span></label></div>');
                                            YSRowsType.append(Content2);
                                            ModContent.append(YSRowsType);

                                            var TimeRows = $('<div class="Rows PreauthorizationTime"><div class="Name"><em>*</em>预授权到期时间：</div></div>');
                                            var Content1 = $('<div class="RowsContent"></div>');
                                            var TimeInput = $('<input class="TimeInput" type="text" readonly/>');
                                            var shijian = Date.parse(new Date()) / 1000;
                                            TimeInput.datetimepicker({
                                                format: "yyyy-mm-dd HH:ii",
                                                language: 'zh-CN',
                                                showMeridian: true,
                                                autoclose: true,
                                                todayBtn: true,
                                                startDate: $().Timestamp.TimestampDate(shijian)
                                            }).on('change', function () {
                                                var Titme = $('body .CustomModalBox[custommodalboxlength="0"] .TimeInput').val();
                                                peccancyForegiftTime = $().Timestamp.DateTimestamp(Titme);
                                            });
                                            Content1.append(TimeInput);
                                            TimeRows.append(Content1);
                                            ModContent.append(TimeRows);
                                            yajinjiluData.data.Content = ModContent;

                                            var rentCar = ModContent.find('.rentCarInput');
                                            for (var i = 0; i < rentCar.length; i++) {
                                                rentCar.eq(i).on('click', function () {
                                                    switch ($(this).val()) {
                                                        case '预授权':
                                                            peccancyForegiftType = 1;
                                                            ModContent.find('.PreauthorizationTime').css({
                                                                'opacity': 1,
                                                                'z-index': '100',
                                                                'display': 'inline-block'
                                                            });
                                                            ;
                                                            break;
                                                        case '现金':
                                                            peccancyForegiftType = 0;
                                                            ModContent.find('.PreauthorizationTime').css({
                                                                'opacity': 1,
                                                                'z-index': '-100',
                                                                'display': 'none'
                                                            });
                                                            break;
                                                    }
                                                })
                                            }

                                            $('body').ModalBox(yajinjiluData);

                                        }
                                    }
                                )
                                break;
                            case 1:
                                val.ViolationOfTheDeposit = data.content[i].peccancyForegift;
                                val.PullDownAction.data.push({
                                    name: "退还违章押金",
                                    action: function (e) {
                                        var SingID = e.parent().parent().parent().parent().data().id;
                                        var SinglePin = {
                                            data: {
                                                Title: '退还违章',
                                                Content: "是否退还违章押金?"
                                                ,
                                                OkChange: function () {
                                                    var Single = {
                                                        id: SingID,
                                                        type: 1
                                                    };
                                                    $.ajax({
                                                        url: ctx + '/rentorder/backForegift',
                                                        data: Single,
                                                        type: 'POST',
                                                        success: function (data, status) {
                                                            if (status == "success") {
                                                                new $().Overlays({
                                                                    data: {
                                                                        text: '违章预售金退还成功！',
                                                                        state: 'Ok'
                                                                    }
                                                                });
                                                            }
                                                            if (status == "error") {
                                                                new $().Overlays({
                                                                    data: {
                                                                        text: '押金退还失败！',
                                                                        state: 'On'
                                                                    }
                                                                });
                                                            }
                                                            ajaxFreshOrder(1)
                                                        }
                                                    })

                                                }
                                            }
                                        };
                                        $('body').ModalBox(SinglePin);
                                    }
                                });
                                break;
                            case 2:
                                val.ViolationOfTheDeposit = '已退还';
                                break;
                        }


                        Message.data.Tbody.push(val);
                    })()

                }


                var PagingMdOption = {
                    data: {
                        rows: 20,
                        nowrows: page,
                        Pages: '',
                        total: data.totalElements,
                        change: function (index) {
                            ajaxFreshOrder(index, SEOval);
                        }
                    }
                };
                PagingMdOption.data.Pages = Math.ceil((PagingMdOption.data.total / PagingMdOption.data.rows));

                $(".Content").find('.CustomOrder').remove();
                $(".Content").find('.PagingMdPagingMd').remove();
                $(".Content").Order(Message);
                $(".Content").PagingMd(PagingMdOption)
            }
        })
    }
});


